package com.zj.easywebview

import android.webkit.WebView
import java.lang.ref.WeakReference

class BridgeCallback internal constructor(
    private val port: Int, webView: WebView?
) {
    private val CALLBACK_JS_MODEL = "javascript:onAndroidFinish('%s', '%s');"

    private val webViewRef by lazy {
        WeakReference(webView)
    }

    fun callBack(callBackData: String?) {
        val execJs = String.format(CALLBACK_JS_MODEL, port, callBackData)
        webViewRef.get()?.apply {
            loadUrl(execJs)
        }
    }
}